package com.jzkj.zsqxkq.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jzkj.zsqxkq.entity.custom.TblMoniSiteChecktimeCustom;
import com.jzkj.zsqxkq.service.ITblMoniSiteChecktimeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 周毅
 * @since 2020-07-06
 */
@Controller
@RequestMapping("/checktime")
public class TblMoniSiteChecktimeController {

    @Resource
    private ITblMoniSiteChecktimeService checktimeService;


    @GetMapping(value = "/siteavg")
    public String getSiteColAvg(Model model, String siteId, Integer pageNum, Integer pageSize) {
        if (null == pageNum || pageNum <= 0) {
            pageNum = 1;
        }
        if (null == pageSize || pageSize <= 0) {
            pageSize = 10;
        }
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> siteAvg = checktimeService.getSiteColAvg(siteId);
        model.addAttribute("pageInfo", new PageInfo<>(siteAvg));

        model.addAttribute("pageSize", pageSize);
        model.addAttribute("pageNum", pageNum);
        return "site-avg";
    }

    @GetMapping(value = "/getcolmax")
    public String getSiteColMax(Model model, String dateStr, Integer pageNum, Integer pageSize) {
        if (null == pageNum || pageNum <= 0) {
            pageNum = 1;
        }
        if (null == pageSize || pageSize <= 0) {
            pageSize = 10;
        }
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> siteColMax = checktimeService.getSiteColMax(dateStr);
        model.addAttribute("pageInfo", new PageInfo<>(siteColMax));
        model.addAttribute("dateStr", dateStr);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute("pageNum", pageNum);
        return "site-max";
    }

    @GetMapping(value = "/getsitecol")
    public String getSiteCol(Model model, Integer pageNum, Integer pageSize) {
        if (null == pageNum || pageNum <= 0) {
            pageNum = 1;
        }
        if (null == pageSize || pageSize <= 0) {
            pageSize = 10;
        }
        PageHelper.startPage(pageNum, pageSize);
        List<TblMoniSiteChecktimeCustom> checktimes = checktimeService.getSiteCol();
        model.addAttribute("pageInfo", new PageInfo<>(checktimes));
        model.addAttribute("pageSize", pageSize);
        model.addAttribute("pageNum", pageNum);
        return "checktime-list";
    }

}
